package com.beiben.quality.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.beiben.quality.domain.QaContractSum;
import com.beiben.quality.service.IQaContractSumService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同数Controller
 * 
 * @author gx
 * @date 2021-03-10
 */
@RestController
@RequestMapping("/contract/contract")
public class QaContractSumController extends BaseController
{
    @Autowired
    private IQaContractSumService qaContractSumService;

    /**
     * 查询合同数列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(QaContractSum qaContractSum)
    {
        startPage();
        List<QaContractSum> list = qaContractSumService.selectQaContractSumList(qaContractSum);
        return getDataTable(list);
    }

    /**
     * 导出合同数列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:export')")
    @Log(title = "合同数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QaContractSum qaContractSum)
    {
        List<QaContractSum> list = qaContractSumService.selectQaContractSumList(qaContractSum);
        ExcelUtil<QaContractSum> util = new ExcelUtil<QaContractSum>(QaContractSum.class);
        return util.exportExcel(list, "contract");
    }

    /**
     * 获取合同数详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return AjaxResult.success(qaContractSumService.selectQaContractSumById(contractId));
    }

    /**
     * 新增合同数
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:add')")
    @Log(title = "合同数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QaContractSum qaContractSum)
    {
        return toAjax(qaContractSumService.insertQaContractSum(qaContractSum));
    }

    /**
     * 修改合同数
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:edit')")
    @Log(title = "合同数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QaContractSum qaContractSum)
    {
        return toAjax(qaContractSumService.updateQaContractSum(qaContractSum));
    }

    /**
     * 删除合同数
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:remove')")
    @Log(title = "合同数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(qaContractSumService.deleteQaContractSumByIds(contractIds));
    }
}
